/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------
#include <google/dense_hash_map>
#include "../token_identity.hpp"
// ----------------------------------------------------------------------------
#ifndef O2_PARSE_PRECEDENCE_MAP_INC
#define O2_PARSE_PRECEDENCE_MAP_INC
namespace o2 {
namespace parse {
// ----------------------------------------------------------------------------

template <typename PrecedenceT>
class basic_precedence_map
{
	public:
		typedef PrecedenceT precedence_type;
		typedef google::dense_hash_map<token_identity, precedence_type, std::tr1::hash<int> > map_type;
		
		basic_precedence_map(void)
		{
			if (s_map.empty())
			{
				s_map.set_empty_key(TOK_UNKNOWN);
				s_map[TOK_ASSIGN] = 100;
				s_map[TOK_LT]  = s_map[TOK_GT]  = 700;
				s_map[TOK_NEG] = s_map[TOK_POS] = 800;
				s_map[TOK_DIV] = s_map[TOK_MUL] = 900;
				s_map[TOK_DOT] = 1000;
			}
		}
		
		precedence_type operator[] (token_identity op) const
		{
			typename map_type::const_iterator iter = s_map.find(op);
			return iter == s_map.end() ? -1 : iter->second;
		}
	
	private:
		static map_type s_map;
};

template <typename PrecedenceT>
typename basic_precedence_map<PrecedenceT>::map_type basic_precedence_map<PrecedenceT>::s_map;

// ----------------------------------------------------------------------------

typedef basic_precedence_map<int> precedence_map;

// ----------------------------------------------------------------------------
} // namespace parse
} // namespace o2
#endif // O2_PARSE_KEYWORD_MAP_INC
// ----------------------------------------------------------------------------
